package com.usooft.metaTalent.db.system.form;

import com.usooft.framework.core.query.Sort;
import com.usooft.framework.web.form.ListForm;
import com.usooft.metaTalent.core.system.query.EmployeeQuery;
import java.lang.Boolean;
import java.lang.Long;
import java.lang.Override;
import java.lang.String;
import java.time.LocalDateTime;
import lombok.Setter;

@Setter
public class EmployeeListForm extends ListForm<EmployeeQuery> {
    private Long idIs;

    private Long[] idIn;

    private LocalDateTime createdDateOnOrBefore;

    private LocalDateTime createdDateOnOrAfter;

    private String phoneNumberIs;

    private String phoneNumberContains;

    private String nameIs;

    private String nameContains;

    private String genderIs;

    private Boolean adminIs;

    private Boolean loginStatusIs;

    private Boolean lockedIs;

    @Override
    public EmployeeQuery buildQuery() {
        return EmployeeQuery.builder()
                                .filter(buildFilter())
                                .sorts(buildSorts())
                                .limit(getLimit())
                                .build();
    }

    private EmployeeQuery.Filter buildFilter() {
        return EmployeeQuery.Filter.builder()
                .idIs(idIs)
                .idIn(idIn)
                .createdDateOnOrBefore(createdDateOnOrBefore)
                .createdDateOnOrAfter(createdDateOnOrAfter)
                .phoneNumberIs(phoneNumberIs)
                .phoneNumberContains(phoneNumberContains)
                .nameIs(nameIs)
                .nameContains(nameContains)
                .genderIs(genderIs)
                .adminIs(adminIs)
                .loginStatusIs(loginStatusIs)
                .lockedIs(lockedIs)
                .build();
    }

    private EmployeeQuery.Sorts buildSorts() {
        EmployeeQuery.Sorts.Builder builder = EmployeeQuery.Sorts.builder();
        for (String sortItem : getSortItems()) {
            Sort.Order order = getSortOrder(sortItem);
            switch (sortItem) {
                case "-id", "id" -> builder.id(order);
            }
        }
        return builder.build();
    }
}
